import axios from "axios";
import router from "../router";

const request = axios.create({
  baseURL: "/api", // url = base url + request url
  withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})
request.interceptors.request.use(config => {
  config.headers = {"Token": localStorage.getItem('token')}
  return config;
},);
request.interceptors.response.use(res => {
  if (res.data.msg === "请重新登录！")
    router.push("/login")
  return res
}, (error) => {
  //这里是请求失败的回调
  console.log(error)
  // alert("服务器错误,请稍后再试。")
  // router.push("/")
},);

export default request;
